
package com.xbongbong.saas.model.impl;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.saas.domain.dao.SurveyAnswerDao;
import com.xbongbong.saas.domain.entity.SurveyAnswerEntity;
import com.xbongbong.saas.model.SurveyAnswerModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;


/**
* @author autoGen
* @time 2018-11-12 20:02:45
*/
@Service("surveyAnswerModel")
public class SurveyAnswerModelImpl implements SurveyAnswerModel {

	@Resource
	private SurveyAnswerDao surveyAnswerDao;

	@Override
	public Integer insert(SurveyAnswerEntity entity) throws XbbException {
		Long now = DateTimeUtil.getInt();
		entity.setAddTime(now);
		entity.setUpdateTime(now);
		return surveyAnswerDao.insert(entity);
	}

	@Override
	public Integer update(SurveyAnswerEntity entity) throws XbbException {
		entity.setUpdateTime(DateTimeUtil.getInt());
		return surveyAnswerDao.update(entity);
	}

	@Override
	public List findEntitys(Map<String, Object> param) {
		return surveyAnswerDao.findEntitys(param);
	}

	@Override
	public Integer getEntitysCount(Map<String, Object> param) {
		return surveyAnswerDao.getEntitysCount(param);
	}

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    @Override
	public Integer save(SurveyAnswerEntity entity) throws XbbException {
		if(entity.getId() == null || Objects.equals(0, entity.getId())) {
			return insert(entity);
		}
		return update(entity);
	}

	@Override
	public void insertBatch(List<SurveyAnswerEntity> entityList) throws XbbException {
		surveyAnswerDao.insertBatch(entityList);
	}

	@Override
	public Integer deleteByKey(Integer key, String corpid) {
		return surveyAnswerDao.deleteByKey(key , corpid);
	}

	@Override
	public SurveyAnswerEntity getByKey(Integer key, String corpid) {
		return surveyAnswerDao.getByKey(key , corpid);
	}
}

